
clear
use phillips_jhr_cleandata


***
***Results
***


***Table 2
	drop jobnum
	gen jobnum = ceil(id/4)
	xtset jobnum

	gen fp = 0
	replace fp =1 if addresstype == "FP"
	gen fa = 0
	replace fa = 1 if addresstype == "FA"
	gen np = 0
	replace np= 1 if addresstype == "NP"

	***Basic Comparisons
	reg response far poor, cluster(jobnum)
	reg response far poor fp, cluster(jobnum)
	xtreg response far poor, cluster(jobnum) fe
	xtreg response far poor white black female work_experience age work_gap profileXjob_*, cluster(jobnum) fe

	*heterogeneous effects by race of name
	foreach var of varlist white black {
		gen `var'Xfar = `var' * far
		gen `var'Xdistance = `var' * distance
	}
	reg response  far blackXfar whiteXfar  black white poor female work_experience age work_gap profileXjob_*, cluster(jobnum)
	lincom blackXfar - whiteXfar


	
*Table 5	
	
	cap tab app_applicantaddress, gen(address_dummy_)
	egen mean_far = mean(far), by(app_applicantaddress)
	gen fe_sample = 0
	replace fe_sample = 1 if mean_far < 1 & mean_far > 0
	cap tab quadrant, gen(quadrant_)

	xtreg response far poor white black female work_experience age work_gap profileXjob_*, cluster(jobnum) fe
	xtreg response  far poor quadrant_1 quadrant_3 quadrant_4 white black female work_experience age work_gap profileXjob_*, cluster(jobnum) fe
	xtreg response  far poor i.tract white black female work_experience age work_gap profileXjob_*, cluster(jobnum) fe
	xtreg response far poor white black female work_experience age work_gap profileXjob_* address_dummy_*, cluster(jobnum) fe
	
	xtreg response far poor white black female work_experience age work_gap profileXjob_* if fe_sample == 1, cluster(jobnum) fe
	xtreg response fa  fp poor white black female work_experience age work_gap profileXjob_* address_dummy_*, cluster(jobnum) fe

		***Access to jobs
		merge 1:1 id using avg_dist_app_tojob.dta
		drop _merge
		gen idio_dist = distance - avg_dist
		gen farXavg_dist = far * avg_dist
		gen poorXavg_dist = poor * avg_dist
		correlate distance avg_dist idio_dist

	xtreg response far poor avg_dist   ///
	white black female work_experience age work_gap profileXjob_*, cluster(jobnum) fe

	***fe_sample tends to be near Northwest DC at expense of SW and SE; SW is almost always far; SW is almost always near; so FE estimates pick up that NW DC employers care more about distance but pretty balanced on poor vs rich
	tab quadrant fe_sample, col
	tab quadrant far, col
	tab fe_samp poor, row
	hist mean_far, by(poor) width(0.01)



	
*Table 3; Continuous Treatment IV Model
	gen affluence = normal(-3.196399 + 0.1704157 * log(median_inc) + 0.009163 * fracwhite/100 + 0.2467624 * fracbacplus/100)

	reg response  distance affluence , cluster(jobnum)
	xtreg response  distance affluence , cluster(jobnum) fe

	ivreg2 response  (distance affluence = far poor), cluster(jobnum) first
	lincom 4.263617*distance + .0362701*affluence
	xtivreg2 response  (distance affluence = far poor), cluster(jobnum) fe
	lincom 4.263617*distance + .0362701*affluence
		
		
*Table 4; Robustness of IV Results	
	gen log_med_inc = log(median_inc)
	gen dist_Sq = distance ^ 2
	
	ivreg2 response  (distance affluence = far poor), cluster(jobnum)		
	ivreg2 response  (distance log_med_inc = far poor), cluster(jobnum)
	ivreg2 response (distance affluence = fp far poor), cluster(jobnum)
	ivreg2 response (distance dist_Sq affluence = fp far poor), cluster(jobnum)
	ivreg2 response ( traveltime affluence = far poor fp), cluster(jobnum)
	ivreg2 response (distance traveltime affluence = fp far poor), cluster(jobnum)

		
*Table 6; robustness to response measure
	reg response far poor, cluster(jobnum)
	reg interview far poor, cluster(jobnum)
	reg rejected far poor, cluster(jobnum)
	reg any_response far poor, cluster(jobnum)

	
	
*Figure 7; response rates against distance

	egen rank = rank(distance), by(poor)
	gen pctile_dist = round(rank/_N,0.05)
	egen mean_dist = mean(distance), by(pctile_dist poor)
	egen mean_response = mean(response), by(pctile_dist poor)
	twoway  (lpolyci response distance if distance <= 9 & poor == 0, degree(1)  acolor(gs14) )  ///
			(lpolyci response distance if distance <= 9 & poor == 1, degree(1) acolor(gs14) ) ///
			(lpoly response distance if distance <= 9 & poor == 0, degree(1) lpattern(dash) lcolor(red))  ///
			(lpoly response distance if distance <= 9 & poor == 1, degree(1) lcolor(blue)) ///
			(scatter mean_response mean_dist if  poor == 0 , mcolor(red) msymbol(X)) ///
			(scatter mean_response mean_dist if  poor == 1, mcolor(blue)) ///
			, xtitle(Distance in miles) ytitle(Callback Rate) ///
			legend(off) ///
			xtick(0(1)9) ylabel(0.1(0.05)0.45) ytick(0.1(0.01)0.44) graphr(color(white)) scheme(s2color)
	drop rank pctile_dist mean_dist mean_response

	

*Figure 1; making tract map for poverty
	clear
	use acs_2015_pov.dta

	gen NAME10 = regexs(1) if regexm(geodisplaylabel, "([0-9]+[.]*[0-9]*)[,]")
	keep NAME10 hc03
	rename hc03 poverty
	save temp1, replace

	clear
	use dctracts
	merge 1:1 NAME10 using temp1
	drop if _merge == 2

	spmap poverty using dctracts-coord.dta, id(tract) ocolor(black) osize(vthin) ///
		clnumber(6) clmethod(custom) clbreaks(0 10 20 40 100 ) ///
		fcolor(Greens) ndfcolor(white) legtitle(Poverty Rate) ndocolor(black) ///
		 ndlabel("[0,1)")
		

	
	
	
	
	







